package test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class ImportManager {
	protected CSV csvParser;
	protected Map<String,Object> records;
	protected List<Object> recordsList;
	
	//protected Map category;
	protected DWCategory category;
	protected String csvFile;
	//protected String xmlFile;
	protected String xmlFolder;
	protected String catalogId;
	protected Params params;

	public ImportManager (Params params) {
		this.params = params;
		this.csvFile = params.get("import");
		//this.xmlFile = params.get("export") ;
		this.xmlFolder = params.get("export") ;

		if ( !(new File(this.xmlFolder)).mkdirs() ) {
		    // Directory creation failed
			System.err.println("Directory creation failed");
			//throw Exception("sdgsdfg");
		}

		this.catalogId = params.get("cId") ;
		this.records = new HashMap<String,Object>();
		this.recordsList = new ArrayList<Object>();
		//this.category = new HashMap();
		this.category = new DWCategory();
/*
		try {
			this.records = new HashMap();
			this.csvParser = new CSV(csvFile);
			while (!this.csvParser.isReady()) {
				CSVLine csvl = this.csvParser.nextLine();
				if (csvl == null) break;
				//im.appendLine(csvl);
				this.appendLine(csvl);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	*/	
		
	}

	protected void parseCSV () {
		try {
			//this.records = new HashMap();
			this.csvParser = new CSV(this.csvFile);
			while (!this.csvParser.isReady()) {
				CSVLine csvl = this.csvParser.nextLine();
				if (csvl == null) break;
				//im.appendLine(csvl);
				this.appendLine(csvl);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.err.println("Exception ImportManager.java parseCSV()");
			e.printStackTrace();
		}
		
		
	}
	

	protected abstract void appendLine(CSVLine line);
	public abstract void exportToDw ();
	//public abstract void exportCatalogToDw (String xmlFile); 
	//public abstract void exportPriceToDw (String xmlFile);
	//public abstract void exportInventoryToDw (String xmlFile);
}
